package com.lagou.edu.listener;

import com.lagou.edu.ioc.ClassPathXmlBeanFactory;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author Kirito
 * @description:
 * @date 2020/04/04
 */
public class ContextLoadListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {

        ServletContext context = servletContextEvent.getServletContext();
        try {
            String Location = context.getInitParameter("contextConfigLocation");
            ClassPathXmlBeanFactory.getInstance().doLoadBean(Location);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("ClassPathXmlBeanFactory init error. ");
        }

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
